//依赖闭包实现单例模式
class SingleObject{
    login(){
        console.log("login...")
    }
}
//静态方法，自执行函数
SingleObject.getInstance = (()=>{
    let instance
    return () =>{
        if (!instance){
            instance = new SingleObject()
        }
        return instance
    }
})()

// 调用
let obj1 = SingleObject.getInstance()
obj1.login()

let obj2 = SingleObject.getInstance()
obj2.login()

console.log('obj1===obj2',obj1===obj2)   //true,通过这样的方法永远为同一个实例

let obj3 = new SingleObject()
obj3.login()
console.log('obj1===obj3',obj1===obj3)    //false

export default {
    SingleObject
}

